<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Pool 类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="collectable.isgarbage.html">« Collectable::isGarbage</a></li>
      <li style="float: right;"><a href="pool.collect.html">Pool::collect »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.pthreads.html">pthreads</a></li>
    <li>Pool 类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.pool" class="reference">

 <h1 class="title">Pool 类</h1>
 

 <div class="partintro"><p class="verinfo">(PECL pthreads &gt;= 2.0.0)</p>


  <div class="section" id="pool.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    Pool 对象是多个 Worker 对象的容器，同时也是它们的控制器。
   </p>
   <p class="para">
    线程池是对 Worker 功能的高层抽象，包括按照 pthreads 需要的方式来管理应用的功能。
   </p>
  </div>


  <div class="section" id="pool.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Pool</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">protected</span>
      <var class="varname"><a href="class.pool.html#pool.props.size">$<var class="varname">size</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">protected</span>
      <var class="varname"><a href="class.pool.html#pool.props.class">$<var class="varname">class</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">protected</span>
      <var class="varname"><a href="class.pool.html#pool.props.workers">$<var class="varname">workers</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">protected</span>
      <var class="varname"><a href="class.pool.html#pool.props.ctor">$<var class="varname">ctor</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">protected</span>
      <var class="varname"><a href="class.pool.html#pool.props.last">$<var class="varname">last</var></a></var>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="pool.collect.html" class="methodname">collect</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type Callable">Callable</a></span> <code class="parameter">$collector</code><span class="initializer"> = ?</span></span>): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="pool.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$class</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$ctor</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.pool.html" class="type Pool">Pool</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span><span class="methodname"><a href="pool.resize.html" class="methodname">resize</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span><span class="methodname"><a href="pool.shutdown.html" class="methodname">shutdown</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="pool.submit.html" class="methodname">submit</a></span>(<span class="methodparam"><span class="type"><a href="class.threaded.html" class="type Threaded">Threaded</a></span> <code class="parameter">$task</code></span>): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="pool.submitTo.html" class="methodname">submitTo</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$worker</code></span>, <span class="methodparam"><span class="type"><a href="class.threaded.html" class="type Threaded">Threaded</a></span> <code class="parameter">$task</code></span>): <span class="type">int</span></div>

   }</div>


  </div>


  <div class="section" id="pool.props">
   <h2 class="title">属性</h2>
   <dl>
    
     <dt id="pool.props.size"><var class="varname">size</var></dt>

     <dd>

      <p class="para">Pool 对象可容纳的 Worker 对象的最大数量</p>
     </dd>

    
    
     <dt id="pool.props.class"><var class="varname">class</var></dt>

     <dd>

      <p class="para">Worker 的类</p>
     </dd>

    
    
     <dt id="pool.props.workers"><var class="varname">workers</var></dt>

     <dd>

      <p class="para">指向 Worker 对象的引用</p>
     </dd>

    
    
     <dt id="pool.props.ctor"><var class="varname">ctor</var></dt>

     <dd>

      <p class="para">构造新的 Worker 对象时所需的参数</p>
     </dd>

    
    
     <dt id="pool.props.last"><var class="varname">last</var></dt>

     <dd>

      <p class="para">最后使用的 Worker 对象在池中的位置偏移量</p>
     </dd>

    
   </dl>

  </div>



 </div>

 

























































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="pool.collect.html">Pool::collect</a> — 回收已完成任务的引用</li><li><a href="pool.construct.html">Pool::__construct</a> — 创建新的 Worker 对象池</li><li><a href="pool.resize.html">Pool::resize</a> — 改变 Pool 对象的可容纳 Worker 对象的数量</li><li><a href="pool.shutdown.html">Pool::shutdown</a> — 停止所有的 Worker 对象</li><li><a href="pool.submit.html">Pool::submit</a> — 提交对象以执行</li><li><a href="pool.submitTo.html">Pool::submitTo</a> — 提交一个任务到特定的 Worker 以执行</li></ul>
</div>
</div></div></body></html>